package com.shenfa.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.shenfa.bean.SystemUserCode;
import com.shenfa.service.SystemUserCodeService;

import com.shenfa.util.ResultObject;

/**
 * 系统管理-用户参数管理 Action
 * 
 * @author 张瑶
 * @date 2011-08-24
 */
public class SystemUserCodeAction extends BaseAction {

	private static final long serialVersionUID = 4648605162346591398L;
	
	@Autowired
	private SystemUserCodeService systemUserCodeService;
	private static Logger log=Logger.getLogger(SystemUserCodeAction.class);
	private SystemUserCode systemUserCode;
	private int start;
	private int limit;

	/**
	 * 模糊查询用户参数信息
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String selectSystemUserCode() {
		log.debug("systemUserCode="+systemUserCode+",start="+start+",limit="+limit);
		List<SystemUserCode> list = systemUserCodeService.selectSystemUserCode(systemUserCode, start, limit);
		result = ResultObject.build("0", list);
		result.put("total", systemUserCodeService.getCount(systemUserCode));

		return SUCCESS;
	}

	/**
	 * 生成用户系统store
	 * 
	 * @return
	 */
	public String doSysStore(){
		log.debug("systemUserCode="+systemUserCode);
		List<SystemUserCode> list = systemUserCodeService.getSysStore();
		result = ResultObject.build("0", list);
		return SUCCESS;
	}
	
	/**
	 * 增加用户参数信息
	 */
	public String insertSystemUserCode() {
		log.debug(systemUserCode.toString());
		int type = systemUserCodeService.insertSystemUserCode(systemUserCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "添加成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	/**
	 * 更新用户参数信息
	 */
	public String updateSystemUserCode() {
		log.debug(systemUserCode.toString());
		int type = systemUserCodeService.updateSystemUserCode(systemUserCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "修改成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	/**
	 * 刪除用户参数信息
	 */
	public String deleteSystemUserCode() {
		log.debug(systemUserCode.toString());
		int type = systemUserCodeService.deleteSystemUserCode(systemUserCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "删除成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	public SystemUserCode getSystemUserCode() {
		return systemUserCode;
	}

	public void setSystemUserCode(SystemUserCode systemUserCode) {
		this.systemUserCode = systemUserCode;
	}
	
	public void setStart(int start) {
		this.start = start;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

}
